local weicheng = fk.CreateSkill {
  name = "lingling__weicheng",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lingling__weicheng"] = "伪诚",
  [":lingling__weicheng"] = "锁定技，当其他角色对你使用【杀】时，若你上回合未对其使用【杀】，其须交给你一张牌或失去1点体力。",

  ["lingling__weicheng_give"] = "交出一张牌",
  ["lingling__weicheng_losehp"] = "失去1点体力",
  ["#lingling__weicheng-choose"] = "伪诚：你须选择一项，或点取消令此%arg无效",
  ["#lingling__weicheng-ask"] = "伪诚：交给 %src 一张牌",
}

weicheng:addEffect(fk.CardUsing, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(weicheng.name) and
        data.card.trueName == "slash" and table.contains(data.tos, player) then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      local turn_events = player.room.logic:getEventsByRule(GameEvent.Turn, 1, function(e)
        if turn_event == nil or e.id < turn_event.id then
          return e.data.who == player
        end
      end, 0)
      if #turn_events == 0 then
        return true
      else
        return #turn_events[1]:searchEvents(GameEvent.UseCard, 1, function(e)
          local use = e.data
          return use.from == player and use.card.trueName == "slash" and table.contains(use.tos, target)
        end) == 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.dead then return end
    if not target.dead then
      local choices = { "lingling__weicheng_losehp" }
      if not data.from:isNude() then
        table.insert(choices, "lingling__weicheng_give")
      end
      table.insert(choices, "Cancel")
      local choice = room:askToChoice(data.from, {
        choices = choices,
        all_choices = { "lingling__weicheng_losehp", "lingling__weicheng_give", "Cancel" },
        skill_name = weicheng.name,
        prompt = "#lingling__weicheng-choose:::" .. data.card:getTypeString(),
      })
      if choice == "lingling__weicheng_give" then
        local card = room:askToCards(data.from, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = weicheng.name,
          prompt = "#lingling__weicheng-ask:" .. player.id,
          cancelable = false,
        })
        if #card > 0 then
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, weicheng.name, nil, true, target)
        end
      elseif choice == "lingling__weicheng_losehp" then
        room:loseHp(data.from, 1, weicheng.name)
      end
    end
  end,
})

return weicheng
